//
//  CacheManager.m
//  STJShop
//
//  Created by super on 16/6/27.
//  Copyright © 2016年 Super. All rights reserved.
//

#import "CacheManager.h"
#import "MCPath.h"
#import <YYKit/YYDiskCache.h>
@interface CacheManager ()


@end

@implementation CacheManager

/**
 @brief 保存本地文件
 
 @param obj      要缓存的对象
 @param fileName 缓存本地的文件名
 */
+ (void)cacheObject:(id) obj fileName:(NSString *) fileName
{
//    dispatch_queue_t queue = dispatch_queue_create("cacheName", DISPATCH_QUEUE_CONCURRENT);
//    dispatch_async(queue, ^{
        NSString *path = [[MCPath getDocumentUserCachePath:@""] stringByAppendingPathComponent:fileName];
        YYDiskCache *yy = [[YYDiskCache alloc] initWithPath:path];
        [yy setObject:obj forKey:fileName];
}

/**
 @brief 读取本地文件
 
 @param fileName 读取文件的文件名
 
 */
+ (id)readFileWithFileName:(NSString *) fileName
{
    NSString *path = [[MCPath getDocumentUserCachePath:@""] stringByAppendingPathComponent:fileName];
//    NSLog(@"readFilePath = %@",path);
    YYDiskCache *yy = [[YYDiskCache alloc] initWithPath:path];
    id props = [yy objectForKey:fileName];    
    return props;
    
}
/**
 @brief 删除本地文件
 
 @param fileName 要删除的文件的名字
 */
+ (void)deleteFileWithFileName:(NSString *) fileName
{
    NSString *path = [[MCPath getDocumentUserCachePath:@""] stringByAppendingPathComponent:fileName];
//    NSLog(@"deleteFilePath = %@",path);
    YYDiskCache *yy = [[YYDiskCache alloc] initWithPath:path];
    [yy removeObjectForKey:fileName];
}

@end
